home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / include / istring.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-24  |  690 b   |  35 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1987, 1988, 1989 Stanford University
  5.    Copyright (c) 1989, Tera Computer Company
  6.  **/
  7.  
  8. #ifndef istring_h
  9. #define istring_h
  10.  
  11. #include <string.h>
  12.  
  13. // strdup allocates and returns a duplicate of the given string.
  14.  
  15. //inline char* strdup (const char* s) {
  16. //    char* dup = new char[strlen(s) + 1];
  17. //    strcpy(dup, s);
  18. //    return dup;
  19. //}
  20.  
  21. //char* strdup (const char* s);
  22.  
  23. // strndup allocates and returns a duplicate of the first len
  24. // characters of the given string.
  25.  
  26. inline char* strndup (const char* s, int len) 
  27. {
  28.     char* dup = new char[len + 1];
  29.     strncpy(dup, s, len);
  30.     dup[len] = '\0';
  31.     return dup;
  32. }
  33.  
  34. #endif
  35.